package com.css.dzj.dzjportal.modules.jgaction.forceAction.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.css.dzj.dzjportal.common.util.R;
import com.css.dzj.dzjportal.common.util.http.HttpClientUtil;
import com.css.dzj.dzjportal.modules.jgaction.forceAction.service.ForceService;
import com.css.dzj.dzjportal.modules.jgaction.forceAction.vo.ApJgxxForceEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;

/**
 * 强制行为
 * @Author WT
 * @Date 2020/4/29
 */
@RestController
@RequestMapping(value = "/getForceAction")
@PropertySource(value = "classpath:base.properties")
public class ForceActionController {

    @Value("${AP_URL}")
   private String AP_URL;

    @Autowired
    private ForceService forceService;

/**
 * 多条件查询强制行为
 */
@GetMapping("/getAllForce")
public R getAllForce(@RequestParam(required = false) String superviseId,
                     @RequestParam(required = false) String forceActionName,
                     @RequestParam(required = false) String implementInstitution,
                     @RequestParam(required = false) Integer pageNo,
                     @RequestParam(required = false) Integer pageSize) {

    HashMap<String, String> map = new HashMap<>();
    map.put("superviseId", superviseId);
    map.put("forceActionName", forceActionName);
    map.put("implementInstitution", implementInstitution);
    map.put("pageNo", pageNo.toString());
    map.put("pageSize", pageSize.toString());
    String msg = HttpClientUtil.doGet(AP_URL + "/force/getWtContation", map);
    JSONObject object = JSON.parseObject(msg);
    return R.ok().put("data", object);
}

/**
 * 查看询强制行为详情
 */
@GetMapping("/getById")
public R getById(@RequestParam  String forceId) {
    HashMap<String,String> map=new HashMap<>();
    map.put("forceId",forceId);
    String URL = AP_URL + "/force/getForceID";
    String msg = HttpClientUtil.doGet(URL,map);
    JSONObject object = JSON.parseObject(msg);
    return R.ok().put("data", object);
}

    /***
     * 获取强制行为总数
     * @return
     */
    @GetMapping("/getcount")
    public R getCount() {

        String msg = HttpClientUtil.doGet(AP_URL + "/force/forceCount");
        JSONObject object = JSON.parseObject(msg);
        return R.ok().put("data", object);
    }

    /**
     * * 多条件导出
     */
    @GetMapping("/exportAll")
    public R exportAll(HttpServletResponse response,
                       @RequestParam String superviseId,
                       @RequestParam(required = false) String forceActionName,
                       @RequestParam(required = false) String implementInstitution)  {
        HashMap<String, String> map = new HashMap<>();
        map.put("superviseId", superviseId);
        map.put("forceActionName", forceActionName);
        map.put("implementInstitution", implementInstitution);
        String msg = HttpClientUtil.doGet(AP_URL + "/force/getWtForceList", map);
      // String JSONStr = JSON.toJSONString(msg);
        List<ApJgxxForceEntity> apJgxxForceEntities = JSON.parseArray(msg,ApJgxxForceEntity.class);

        forceService.exportForceToExcel(response,apJgxxForceEntities);
        return R.ok();
    }

    /**
     * 通过ids导出选中数据
     * @param
     * @param
     */
    @GetMapping("/exportByIds")
    public R exportByIds(HttpServletResponse response, @RequestParam String ids){

        String url=AP_URL+"/force/getWtForceIds";
        HashMap<String,String> map=new HashMap<>();
        map.put("ids",ids);
        String msg = HttpClientUtil.doGet(url,map);
        List<ApJgxxForceEntity> apJgxxForceEntities = JSON.parseArray(msg,ApJgxxForceEntity.class);
        forceService.exportForceToExcel(response,apJgxxForceEntities);
        return R.ok();
    }



}
